// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class PEX_CAUSE_PEX_P08 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("23 PCR",23)]
  	    [HL7Field(HL7Version.v23, 23, HL7Repeat.False, HL7Required.True,"PCR")]
	    public PCR PCR {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("24 RX_ORDER",24)]
  	    [HL7Field(HL7Version.v23, 24, HL7Repeat.False, HL7Required.False,"RX_ORDER_PEX_P08")]
	    public RX_ORDER_PEX_P08 RX_ORDER {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("32 RX_ADMINISTRATION",32)]
  	    [HL7Field(HL7Version.v23, 32, HL7Repeat.False, HL7Required.False,"RX_ADMINISTRATION_PEX_P08")]
	    public RX_ADMINISTRATION_PEX_P08 RX_ADMINISTRATION {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			PCR = PopSegmentParseAndCheckRequired<PCR>(availableData, options, "PCR");
			RX_ORDER = ProcessGroup<RX_ORDER_PEX_P08>(availableData, options, "RX_ORDER");
			RX_ADMINISTRATION = ProcessGroup<RX_ADMINISTRATION_PEX_P08>(availableData, options, "RX_ADMINISTRATION");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isPCR = availableData.StartsWith("PCR", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("PCR", options.Version) || isPCR) {
				return isPCR;
			}
			RX_ORDER_PEX_P08 testRX_ORDER_PEX_P08 = new RX_ORDER_PEX_P08();
			bool grpCCRX_ORDER_PEX_P08 = (testRX_ORDER_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("RX_ORDER", options.Version) || grpCCRX_ORDER_PEX_P08) {
				return grpCCRX_ORDER_PEX_P08;
			}
			RX_ADMINISTRATION_PEX_P08 testRX_ADMINISTRATION_PEX_P08 = new RX_ADMINISTRATION_PEX_P08();
			bool grpCCRX_ADMINISTRATION_PEX_P08 = (testRX_ADMINISTRATION_PEX_P08.CanConsume(availableData, options));
			if (IsRequired("RX_ADMINISTRATION", options.Version) || grpCCRX_ADMINISTRATION_PEX_P08) {
				return grpCCRX_ADMINISTRATION_PEX_P08;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "PEX_CAUSE";
			}
        }

        static PEX_CAUSE_PEX_P08() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(PEX_CAUSE_PEX_P08));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (PCR != null) {
			string segmentValue = PCR.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RX_ORDER != null) {
			string segmentValue = RX_ORDER.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (RX_ADMINISTRATION != null) {
			string segmentValue = RX_ADMINISTRATION.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

